<template>
  <div class="main">
    <!-- 头部导航栏 -->
    <head-component
      :noBack="false"
      title="信贷秘籍"/>

    <div class="con">
      <!--banner-->
      <van-swipe :autoplay="3500" class="banner">
        <van-swipe-item @click="location.href = item.b_link" v-for="(item,i) in bannerImg" :key="i"><img :src="item.b_img" alt=""></van-swipe-item>
      </van-swipe>
      <!-- 内容列表 -->
      <div class="list" v-for="(item,i) in ghList" :key="i" @click="toPage(item.id, item.news_title)" >
        <div class="left">
          <p class="f30 col_33 twoLine">{{item.news_title}}</p>
          <!-- <div  class="f24 col_99">{{item.news_addtime}}</div> -->
        </div>
        <img :src="item.news_img" alt="">
      </div>
      <!-- 如果内容列表为空 -->
      <div class="null_list" v-if="ghList == ''">
        <img class="null_img" src="@/common/icon/nothing.png" alt="">
        <div class="null_title">暂无数据</div>
      </div>
    </div>
  </div>
</template>

<script>
import headComponent from '@/components/layout/head'
export default {
    name: "ganhuo.vue",
    data() {
      return {
        ghList:[],
        userStatus:0,
        bannerImg: []
      }
    },
  created() {
    var $this = this;
    var t = this.$toast.loading({message: '正在加载数据', mask: true, duration: 9999})
    var data = {u_id: localStorage.getItem('uid'), token: localStorage.getItem('token')};
    $this.$axios.post('index.php?m=index&c=consult', data)
      .then((res) => {
        t.clear();
        if (res.data.code == 1) {
          res.data.news.map((item, index) => {
            if(item.c_id == 15){
              let obj={
                c_id: item.c_id,
                id: item.id,
                news_addtime: item.news_addtime,
                news_content: item.news_content,
                news_img: item.news_img,
                news_looks: item.news_looks,
                news_title: item.news_title,
                news_tui: item.news_tui,
                news_type: item.news_type
              }
              $this.ghList.unshift(obj);
            }
          })
        } else {
          $this.$router.push('/login');
        }
      });

    // 轮播图
    $this.$axios.post('index.php?m=index&c=technology', data)
      .then((res) => {
        t.clear();
        if (res.data.code == 1) {
          this.bannerImg = res.data.banner
        } else {
          // $this.$router.push('/login');
        }
      });
    //  个人信息
    var data2 = {u_id: localStorage.getItem('uid'),token:localStorage.getItem('token')};
    $this.$axios.post('index.php?m=user&c=index',data2)
      .then((res) => {
        if(res.data.code == 1){
          this.userStatus = res.data.user.m_level;
        }else{
          this.$router.push('/login');
        }
      });
  },
  methods:{
    toPage(id, text){
      var $this = this;
      if($this.userStatus != 0){
        $this.$router.push({path:'/ganhuoD', query:{id:id,type:1,title:text}})
      }else{
        $this.$toast({
          message: '请先开通VIP',
          duration: 800,
          onClose: ()=> {
            $this.$router.push('/vip');
          }
        })
      }
    },
  },
  components: {
    headComponent,
  },
}
</script>
<style scoped lang="less">
  .twoLine{overflow:hidden;display:-webkit-box;text-overflow: ellipsis;-webkit-line-clamp:2;-webkit-box-orient: vertical;white-space: normal;}
  .main{width: 100%;height: 100%;background: #fff; overflow: scroll}
  .layout-head{border-bottom: 0.02rem solid #f5f5f5;}
  .con{width: 92%; margin: 1.2rem auto 0.9rem;
    .banner{
      width: 100%;
      margin: 0.2rem auto;
      height: 4rem;
      div{
        width: 100%;height: 100%;}
      img{
        width:100%;
        height: 100%;
        border-radius: 0.16rem;
      }
      .mint-swipe-indicators{background: rgba(255,255,255,0.5)!important;width: 0.3rem!important;height: 0.3rem!important;}
      .is-active{background: rgba(255,255,255,1)!important;}
    }
    .list{
      width: 100%;
      padding: 0.3rem 0;
      border-bottom: 0.02rem solid #f5f5f5;
      overflow: hidden;
      display: flex;
      display: -webkit-flex;
      justify-content: space-between;
      -webkit-justify-content: space-between;
      align-items: center;
      -webkit-align-items: center;
      img{
        height: 1rem;
        border-radius: 0.12rem;
        float: right;
      }
    }
    .null_list{ margin-top: 5rem; }
  }
</style>

